import java.util.concurrent.atomic.AtomicInteger;

public class ThreadDemo1 {
    public static void main(String[] args) throws InterruptedException {
        AtomicInteger num=new AtomicInteger(0);
        Thread t=new Thread(()->{
            for (int i = 0; i <5000 ; i++) {
                      num.getAndIncrement(); //num++;
            }
        });
        Thread t1=new Thread(()->{
            for (int i = 0; i <5000 ; i++) {
                 num.getAndIncrement();
            }
        }) ;
        t.start();
        t1.start();
        t.join();
        t1.join();
        System.out.println(num.get()); //这个方法可以得到原子类内部的数值
    }
}
